package com.ssy.lingxi.product.common.enums;

import com.ssy.lingxi.common.language.LanguageHolder;
import com.ssy.lingxi.product.model.resp.MaterialInnerStatusResponse;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Objects;
import java.util.stream.Collectors;

/**
 * 物料变更/启用外部流程状态
 *
 * @author pengdd
 * @version 2.0.0
 * @date 2022/3/24
 */
public enum MaterialsChangeOrEnableInternalStatusEnum {
    /**
     * 待提交审核
     */
    PENDING_SUBMISSION(51, "待提交审核", "变更"),
    /**
     * 待审核物料（一级）
     */
    TO_BE_REVIEWED_LEVEL_1(52, "待审核物料（一级）", "启用"),
    /**
     * 一级审核不通过
     */
    FAILED_TO_PASS_THE_FIRST_LEVEL_AUDIT(53, "一级审核不通过", "提交"),
    /**
     * 待审核（二级）
     */
    TO_BE_REVIEWED_LEVEL_2(54, "待审核物料（二级）", "提交"),
    /**
     * 二级审核不通过
     */
    FAILED_TO_PASS_THE_SECONDARY_AUDIT(55, "二级审核不通过", ""),
    /**
     * 已确认
     */
    CONFIRMED(99, "已确认", "审核物料（二级）"),
    ;

    private final Integer code;
    private final String message;
    private final String operational;

    MaterialsChangeOrEnableInternalStatusEnum(Integer code, String message, String operational) {
        this.code = code;
        this.message = message;
        this.operational = operational;
    }

    public Integer getCode() {
        return this.code;
    }

    public String getMessage() {
        String key = "MaterialsChangeOrEnableInternalStatusEnum.".concat(String.valueOf(this.getCode()));
        return LanguageHolder.getName(key);
    }

    public static String getMessage(Integer code) {
        return Arrays.stream(MaterialsChangeOrEnableInternalStatusEnum.values()).filter(f -> Objects.equals(f.getCode(), code)).findFirst().map(MaterialsChangeOrEnableInternalStatusEnum::getMessage).orElse("");
    }

    public String getOperational() {
        String key = "MaterialsChangeOrEnableInternalStatusEnum.c.".concat(String.valueOf(this.getCode()));
        return LanguageHolder.getName(key);
    }

    public static String getOperational(Integer code) {
        return Arrays.stream(MaterialsChangeOrEnableInternalStatusEnum.values()).filter(f -> Objects.equals(f.getCode(), code)).findFirst().map(MaterialsChangeOrEnableInternalStatusEnum::getOperational).orElse("");
    }

    /**
     * 获取99之外的枚举code
     *
     * @return list
     */
    public static List<Integer> getCodeList() {
        return Arrays.stream(MaterialsChangeOrEnableInternalStatusEnum.values()).map(MaterialsChangeOrEnableInternalStatusEnum::getCode).filter(fCode -> !Objects.equals(fCode, MaterialsChangeOrEnableInternalStatusEnum.CONFIRMED.getCode())).collect(Collectors.toList());
    }

    /**
     * 获取51,53,55的枚举code
     *
     * @return list
     */
    public static List<Integer> getAssignCodeList() {
        return Arrays.asList(MaterialsChangeOrEnableInternalStatusEnum.PENDING_SUBMISSION.getCode(), MaterialsChangeOrEnableInternalStatusEnum.FAILED_TO_PASS_THE_FIRST_LEVEL_AUDIT.getCode(), MaterialsChangeOrEnableInternalStatusEnum.FAILED_TO_PASS_THE_SECONDARY_AUDIT.getCode());
    }

    /**
     * 封装全部枚举
     *
     * @return list
     */
    public static List<MaterialInnerStatusResponse> getInnerStatus() {
        List<MaterialInnerStatusResponse> materialInnerStatusResponses = new ArrayList<>();
        for (MaterialsChangeOrEnableInternalStatusEnum materialsChangeOrEnableInternalStatusEnum : MaterialsChangeOrEnableInternalStatusEnum.values()) {
            MaterialInnerStatusResponse response = new MaterialInnerStatusResponse();
            response.setStatus(materialsChangeOrEnableInternalStatusEnum.getCode());
            response.setName(materialsChangeOrEnableInternalStatusEnum.getMessage());
            materialInnerStatusResponses.add(response);
        }
        return materialInnerStatusResponses;
    }
}
